/*
 * @Author: fhw
 * @Date: 2022-07-17 13:35:20
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-02-07 11:20:48
 * @Description: 数据模型
 */
import { ApiProperty } from '@nestjs/swagger';
import { ChatUser } from 'src/chat_user/entities/chat_user.entity';
import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  OneToMany,
  UpdateDateColumn,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { CommentList } from '../../article_comment/entities/article_comment.entity';
import { PaginatedResult } from '../../common/entities/entities';
@Entity('article')
export class ArticleList {
  @ApiProperty({ example: 'id', description: 'id' })
  @PrimaryGeneratedColumn({
    type: 'int',
    comment: 'id',
  })
  id: number;

  @ApiProperty({ example: 'title', description: '文章标题' })
  @Column({
    type: 'varchar',
    length: 100,
    comment: '文章标题',
  })
  title: string;

  @ApiProperty({ example: 'content', description: '文章内容' })
  @Column({ type: 'text', comment: '文章内容', nullable: true, })
  content: string;

  @ApiProperty({ example: 'tags', description: '标签' })
  @Column({
    type: 'varchar',
    length: 256,
    comment: '标签',
    nullable: true,
  })
  tags: string;

  @ApiProperty({ example: 'date', description: '创建时间' })
  @CreateDateColumn({
    type: 'datetime',
    comment: '创建时间',
  })
  createDate: string;

  @ApiProperty({ example: 'updateDate', description: '更新时间' })
  @UpdateDateColumn({
    type: 'datetime',
    comment: '更新时间',
  })
  updateDate: string;
  
  @ApiProperty({
    example: 'abstract',
    description: '文章摘要',
  })
  @Column({
    type: 'varchar',
    length: 256,
    nullable: true,
    comment: '文章摘要',
  })
  abstract: string;

  @ApiProperty({ example: 'category', description: '文章分类' })
  @Column({
    type: 'varchar',
    length: 256,
    comment: '文章分类',
    nullable: true,
  })
  category: string;

  @ApiProperty({ example: 'imageUrl', description: '文章封面' })
  @Column({
    type: 'varchar',
    length: 256,
    nullable: true,
    comment: '文章封面',
  })
  imageUrl: string;

  @ApiProperty({ example: 'read', description: '阅读量' })
  @Column({
    type: 'int',
    default: 0,
    comment: '阅读量',
  })
  read: number;

  @ApiProperty({ example: 'status', description: '0:保存草稿，1:发布，2:删除' })
  @Column({
    type: 'enum',
    default: 0,
    comment: '0:保存草稿，1:发布，2:删除',
    enum: [0, 1, 2],
  })
  status: number;

  @ApiProperty({ example: 'userId', description: '发布者id' })
  @Column({
    type: 'int',
    nullable: true,
    comment: '发布者id',
  })
  userId: number;
  @ManyToOne(() => ChatUser, (user) => user.id)
  @JoinColumn()
  user: ChatUser;
  
  @ApiProperty({ example: 'thumbUp', description: '点赞' })
  @Column({
    type: 'int',
    default: 0,
    comment: '点赞数',
  })
  thumbUp: number;

  @ApiProperty({ example: 'comment', description: '评论' })
  @OneToMany(() => CommentList, (comment) => comment.article)
  comment?: CommentList[];
}
export class ArticleResult extends PaginatedResult {
  @ApiProperty({
    example: ArticleList,
    type: [ArticleList],
  })
  data: ArticleList[];
  @ApiProperty({ example: 'pageSize', description: '数量' })
  pageSize: number;
  @ApiProperty({ example: 'pageNum', description: '页数' })
  pageNum: number;
  @ApiProperty({ example: 'total', description: '总数' })
  total: number;
}
export class ArticleIdAndTitle {
  @ApiProperty({ example: 'id', description: 'id' })
  id: number;
  @ApiProperty({ example: 'title', description: '文章标题' })
  title: string;
}
export class ArticleInfo {
  @ApiProperty({
    example: ArticleList,
    type: ArticleList,
    description: '文章详情',
  })
  data: ArticleList;
  @ApiProperty({
    example: ArticleIdAndTitle,
    type: ArticleIdAndTitle,
    description: '上一条文章',
  })
  prev: ArticleList;
  @ApiProperty({
    example: ArticleIdAndTitle,
    type: ArticleIdAndTitle,
    description: '下一条文章',
  })
  next: ArticleList;
}
